package com.lw.vue_shop_server.controller;

import com.lw.vue_shop_server.service.impl.GoodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class GoodController {
    @Autowired
    public GoodServiceImpl goodService;

    @GetMapping("/goodnum")
    public Map getGoodnum(){
        return goodService.getGoodnum();
    }

    @GetMapping("/goods")
    public Map getGoodList(HttpServletRequest request){
        Integer pagenum = Integer.parseInt(request.getParameter("pagenum"));
        Integer pagesize = Integer.parseInt(request.getParameter("pagesize"));
        return goodService.getGoodList(pagenum,pagesize);
    }

    @DeleteMapping("/goods/{id}")
    public Map delGoodById(@PathVariable(value = "id")Integer id){
        return goodService.delGoodById(id);
    }
}
